<%@ CodePage = 65001 %>
<!--#include file="ewconfig.asp"-->
<!--#include file="db.asp"-->
<!--#include file="FS_GLX_Xuatchieuinfo.asp"-->
<!--#include file="advsecu.asp"-->
<!--#include file="aspmkrfn.asp"-->
<!--#include file="ewupload.asp"-->
<%
Response.expires = 0
Response.expiresabsolute = Now() - 1
Response.addHeader "pragma", "no-cache"
Response.addHeader "cache-control", "private"
Response.addHeader "cache-control", "no-cache"
Response.addHeader "cache-control", "no-store"
Response.CacheControl = "no-cache"
%>
<%

' Initialize common variables
x_RapID = Null: ox_RapID = Null: z_RapID = Null
x_GiochieuID = Null: ox_GiochieuID = Null: z_GiochieuID = Null
x_FilmId = Null: ox_FilmId = Null: z_FilmId = Null
x_Mota = Null: ox_Mota = Null: z_Mota = Null
x_Gia = Null: ox_Gia = Null: z_Gia = Null
x_Ngaychieu = Null: ox_Ngaychieu = Null: z_Ngaychieu = Null
%>
<%
Response.Buffer = True

' Load Key Parameters
sKey = "": bSingleDelete = True
x_RapID = Request.QueryString("RapID")
If x_RapID <> "" Then
	If sKey <> "" Then sKey = sKey & ","
	sKey = sKey & x_RapID
Else
	bSingleDelete = False
End If
x_GiochieuID = Request.QueryString("GiochieuID")
If x_GiochieuID <> "" Then
	If sKey <> "" Then sKey = sKey & ","
	sKey = sKey & x_GiochieuID
Else
	bSingleDelete = False
End If
x_Ngaychieu = Request.QueryString("Ngaychieu")
If x_Ngaychieu <> "" Then
	If sKey <> "" Then sKey = sKey & ","
	sKey = sKey & x_Ngaychieu
Else
	bSingleDelete = False
End If
If Not bSingleDelete Then
	sKey = Request.Form("key_d")
End If
If sKey = "" Or IsNull(sKey) Then Response.Redirect "FS_GLX_Xuatchieulist.asp"
arRecKey = Split(sKey&"", ",")
i = 0
Do While i <= UBound(arRecKey)
	sDbWhere = sDbWhere & "("

	' Remove spaces
	sRecKey = Trim(arRecKey(i+0))

	' Build the SQL
	sDbWhere = sDbWhere & "[RapID]=" & AdjustSql(sRecKey) & " AND "

	' Remove spaces
	sRecKey = Trim(arRecKey(i+1))

	' Build the SQL
	sDbWhere = sDbWhere & "[GiochieuID]=" & AdjustSql(sRecKey) & " AND "

	' Remove spaces
	sRecKey = Trim(arRecKey(i+2))

	' Build the SQL
	sDbWhere = sDbWhere & "[Ngaychieu]='" & AdjustSql(sRecKey) & "' AND "
	If Right(sDbWhere, 5) = " AND " Then sDbWhere = Left(sDbWhere, Len(sDbWhere)-5) & ") OR "
	i = i + 3
Loop
If Right(sDbWhere, 4) = " OR " Then sDbWhere = Left(sDbWhere, Len(sDbWhere)-4)

' Get action
sAction = Request.Form("a_delete")
If sAction = "" Or IsNull(sAction) Then
	sAction = "D"	' Delete record directly
End If

' Open connection to the database
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open xDb_Conn_Str
Select Case sAction
	Case "I": ' Display
		If LoadRecordCount(sDbWhere) <= 0 Then
			conn.Close ' Close Connection
			Set conn = Nothing
			Response.Clear
			Response.Redirect "FS_GLX_Xuatchieulist.asp"
		End If
	Case "D": ' Delete
		If DeleteData(sDbWhere) Then
			Session(ewSessionMessage) = "Delete Successful"
			conn.Close ' Close Connection
			Set conn = Nothing
			Response.Clear
			Response.Redirect "FS_GLX_Xuatchieulist.asp"
		End If
End Select
%>
<!--#include file="header.asp"-->
<p><span class="aspmaker">Delete from TABLE: FS GLX Xuatchieu<br><br><a href="FS_GLX_Xuatchieulist.asp">Back to List</a></span></p>
<form action="FS_GLX_Xuatchieudelete.asp" method="post">
<p>
<input type="hidden" name="a_delete" value="D">
<input type="hidden" name="key_d" value="<%= sKey %>">
<table class="ewTable">
	<tr class="ewTableHeader">
		<td valign="top"><span>Rap ID</span></td>
		<td valign="top"><span>Giochieu ID</span></td>
		<td valign="top"><span>Film Id</span></td>
		<td valign="top"><span>Mota</span></td>
		<td valign="top"><span>Gia</span></td>
		<td valign="top"><span>Ngaychieu</span></td>
	</tr>
<%
nRecCount = 0
i = 0
Do While i <= UBound(arRecKey)
	nRecCount = nRecCount + 1

	' Set row color
	sItemRowClass = " class=""ewTableRow"""

	' Display alternate color for rows
	If nRecCount Mod 2 <> 0 Then
		sItemRowClass = " class=""ewTableAltRow"""
	End If
	sRecKey = Trim(arRecKey(i+0))
	x_RapID = sRecKey
	sRecKey = Trim(arRecKey(i+1))
	x_GiochieuID = sRecKey
	sRecKey = Trim(arRecKey(i+2))
	x_Ngaychieu = sRecKey
	If LoadData() Then
%>
	<tr<%=sItemRowClass%>>
		<td><span>
<%
If Not IsNull(x_RapID) Then
	sSqlWrk = "SELECT [TenRap] FROM [FS_GLX_Cinema]"
	sTmp = x_RapID
	sSqlWrk = sSqlWrk & " WHERE [RapID] = '" & AdjustSql(sTmp) & "'"
	Set rswrk = conn.Execute(sSqlWrk)
	If Not rswrk.Eof Then
		sTmp = rswrk("TenRap")
	End If
	rswrk.Close
	Set rswrk = Nothing
Else
	sTmp = Null
End If
ox_RapID = x_RapID ' Backup Original Value
x_RapID = sTmp
%>
<% Response.Write x_RapID %>
<% x_RapID = ox_RapID ' Restore Original Value %>
</span></td>
		<td><span>
<%
If Not IsNull(x_GiochieuID) Then
	sSqlWrk = "SELECT [Mota] FROM [FS_GLX_Giochieu]"
	sTmp = x_GiochieuID
	sSqlWrk = sSqlWrk & " WHERE [GiochieuID] = " & AdjustSql(sTmp) & ""
	Set rswrk = conn.Execute(sSqlWrk)
	If Not rswrk.Eof Then
		sTmp = rswrk("Mota")
	End If
	rswrk.Close
	Set rswrk = Nothing
Else
	sTmp = Null
End If
ox_GiochieuID = x_GiochieuID ' Backup Original Value
x_GiochieuID = sTmp
%>
<% Response.Write x_GiochieuID %>
<% x_GiochieuID = ox_GiochieuID ' Restore Original Value %>
</span></td>
		<td><span>
<%
If Not IsNull(x_FilmId) Then
	sSqlWrk = "SELECT [Title] FROM [FilmArticle]"
	sTmp = x_FilmId
	sSqlWrk = sSqlWrk & " WHERE [ArticleID] = " & AdjustSql(sTmp) & ""
	sSqlWrk = sSqlWrk & " ORDER BY [DateCreated] Desc"
	Set rswrk = conn.Execute(sSqlWrk)
	If Not rswrk.Eof Then
		sTmp = rswrk("Title")
	End If
	rswrk.Close
	Set rswrk = Nothing
Else
	sTmp = Null
End If
ox_FilmId = x_FilmId ' Backup Original Value
x_FilmId = sTmp
%>
<% Response.Write x_FilmId %>
<% x_FilmId = ox_FilmId ' Restore Original Value %>
</span></td>
		<td><span>
<%= Replace(x_Mota&"", vbLf, "<br>") %>
</span></td>
		<td><span>
<% Response.Write x_Gia %>
</span></td>
		<td><span>
<% If IsDate(x_Ngaychieu) Then Response.Write EW_FormatDateTime(x_Ngaychieu,2) Else Response.Write x_Ngaychieu End If %>
</span></td>
	</tr>
<%
	End If
	i = i + 3
Loop
%>
</table>
<p>
<input type="submit" name="Action" value="CONFIRM DELETE">
</form>
<%
conn.Close ' Close Connection
Set conn = Nothing
%>
<!--#include file="footer.asp"-->
<%

'-------------------------------------------------------------------------------
' Function LoadData
' - Load Data based on Key Value
' - Variables setup: field variables

Function LoadData()
	Dim rs, sSql, sFilter
	sFilter = ewSqlKeyWhere
	sFilter = Replace(sFilter, "@RapID", AdjustSql(x_RapID)) ' Replace key value
	sFilter = Replace(sFilter, "@GiochieuID", AdjustSql(x_GiochieuID)) ' Replace key value
	sFilter = Replace(sFilter, "@Ngaychieu", AdjustSql(x_Ngaychieu)) ' Replace key value
	sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, sFilter, "")
	Set rs = Server.CreateObject("ADODB.Recordset")
	rs.Open sSql, conn
	If rs.Eof Then
		LoadData = False
	Else
		LoadData = True
		rs.MoveFirst

		' Get the field contents
		x_RapID = rs("RapID")
		x_GiochieuID = rs("GiochieuID")
		x_FilmId = rs("FilmId")
		x_Mota = rs("Mota")
		x_Gia = rs("Gia")
		x_Ngaychieu = rs("Ngaychieu")
	End If
	rs.Close
	Set rs = Nothing
End Function
%>
<%

'-------------------------------------------------------------------------------
' Function LoadRecordCount
' - Load Record Count based on input sql criteria sqlKey

Function LoadRecordCount(sqlKey)
	Dim rs, sSql, sFilter
	sFilter = sqlKey
	sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, sFilter, "")
	Set rs = Server.CreateObject("ADODB.Recordset")
	rs.CursorLocation = 3
	rs.Open sSql, conn, 1, 2
	LoadRecordCount = rs.RecordCount
	rs.Close
	Set rs = Nothing
End Function
%>
<%

'-------------------------------------------------------------------------------
' Function DeleteData
' - Delete Records based on input sql criteria sqlKey

Function DeleteData(sqlKey)
	Dim rs, sSql, sFilter
	sFilter = sqlKey
	sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, sFilter, "")
	Set rs = Server.CreateObject("ADODB.Recordset")
	rs.CursorLocation = 3
	rs.Open sSql, conn, 1, 2

	' Clone old rs object
	Dim rsold
	Set rsold = rs.Clone(1)
	rsold.Requery

	' Call recordset deleting event
	DeleteData = Recordset_Deleting(rs)
	If DeleteData Then
		Do While Not rs.Eof
			rs.Delete
			rs.MoveNext
		Loop
	End If
	rs.Close
	Set rs = Nothing

	' Call recordset deleted event
	If DeleteData Then
		Call Recordset_Deleted(rsold)
	End If
	rsold.Close
	Set rsold = Nothing
End Function

'-------------------------------------------------------------------------------
' Recordset deleting event

Function Recordset_Deleting(rsold)
	On Error Resume Next

	' Please enter your customized codes here
	Recordset_Deleting = True
End Function

'-------------------------------------------------------------------------------
' Recordset deleted event

Sub Recordset_Deleted(rsold)
	On Error Resume Next
End Sub
%>
